package ifyou.bdportal.business.vinbom.kafka.consumer;

import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.config.SaslConfigs;
import org.apache.kafka.common.config.SslConfigs;

import java.util.Collections;
import java.util.Properties;

public class SCRMDemo {

    public static void main(String[] args) {
        Properties props = new Properties();
        // props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "alikafka-pre-cn-2r42p51r6001-1-vpc.alikafka.aliyuncs.com:9092,alikafka-pre-cn-2r42p51r6001-2-vpc.alikafka.aliyuncs.com:9092,alikafka-pre-cn-2r42p51r6001-3-vpc.alikafka.aliyuncs.com:9092");
        // props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "10.250.22.71:9092,10.250.22.72:9092,10.250.22.73:9092");
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "10.246.162.120:19092,10.246.162.120:19093,10.246.162.120:19094");
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "crm-opportuniry-transfer");
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");

        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
        consumer.subscribe(Collections.singletonList("scrm-opportunity-transfer"));

        while (true) {
            ConsumerRecords<String, String> records = consumer.poll(10);
            for (ConsumerRecord<String, String> record : records) {
                System.out.println("Received message: (" + record.key() + ", " + record.value() + ") at offset " + record.offset());
            }
        }
    }

}
